<%--
  Created by IntelliJ IDEA.
  User: wenze-zero
  Date: 2021-06-08-008
  Time: 下午 07:37
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.sql.*" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    String id=request.getParameter("id");
    String name=request.getParameter("username");
    String password=request.getParameter("password");

    try {
        Class.forName ("com.mysql.jdbc.Driver");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    Connection conn = null;
    try {
        conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?serverTimezone=Asia/Shanghai", "root", "20010812");
    } catch (SQLException throwables) {
        throwables.printStackTrace();
    }
    out.println("数据库链接成功"+"<br>");
    String sql="insert into student values(?,?,?)";
    PreparedStatement ps= null;
    try {
        assert conn != null;
        ps = conn.prepareStatement(sql);
    } catch (SQLException throwables) {
        throwables.printStackTrace();
    }
    try {
        assert ps != null;
        ps.setString(1,id);
    } catch (SQLException throwables) {
        throwables.printStackTrace();
    }
    try {
        ps.setString(2,name);
    } catch (SQLException throwables) {
        throwables.printStackTrace();
    }
    try {
        ps.setString(3,password);
    } catch (SQLException throwables) {
        throwables.printStackTrace();
    }
    int i= 0;
    try {
        i = ps.executeUpdate();
    } catch (SQLException throwables) {
        throwables.printStackTrace();
    }
    out.println("插入"+i+"条成功！");
    try {
        ps.close();
    } catch (SQLException throwables) {
        throwables.printStackTrace();
    }
    try {
        conn.close();
    } catch (SQLException throwables) {
        throwables.printStackTrace();
    }
%>
</body>
</html>
